package com.sskj.gocoin.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.sskj.common.util.ImgUtil;
import com.sskj.gocoin.R;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.utils.ImageUtil;
import com.sskj.gocoin.utils.ToastUtil;

import java.util.List;

public class HbAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<String> data;

    public HbAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_hb, parent, false);
        return new HbViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HbViewHolder) {
            ImageUtil.setImage(data.get(position), ((HbViewHolder) holder).hbIv);

            ((HbViewHolder) holder).hbIv.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    ImgUtil.saveImageToGallery(context, ((HbViewHolder) holder).hbIv);
                    ToastUtil.showShort(App.INSTANCE.getString(R.string.strImgUtils201));
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    private class HbViewHolder extends RecyclerView.ViewHolder {
        private ImageView hbIv;

        public HbViewHolder(View itemView) {
            super(itemView);
            hbIv = itemView.findViewById(R.id.iv_item_hb);
        }
    }
}
